package com.集合.HashSet;

import java.util.Objects;

public class Student {
    private String name;
    private int age;

    public Student(){}
    public Student(String name,int age){
        this.name = name;
        this.age = age;
    }

    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name = name;
    }
    public int getAge(){
        return age;
    }
    public void setAge(int age){
        this.age = age;
    }

//    @Override
//    public int hashCode() {
//        int result = name != null ? name.hashCode() : 0;
//        result = 31 * result + age;
//        return result;
//    }*/

    //重写equals()方法
    public boolean equals(Object o){
        if(this==o) return true;
        //getClass()方法:返回此Object的运行时类
        if(o==null||getClass()!=o.getClass()) return false;

        Student s = (Student)o;

        if(age!=s.age) return false;

//        return name!=null ? name.equals(s.name) : s.name == null;
        return Objects.equals(name, s.name);
    }
    //重写hashCode()方法
    public int hashCode(){
        int result = name!=null ? name.hashCode() : 0;
        result = 31*result +age;

        return result;
    }
}
